jQuery(document).ready(function () {
	/* var abc = "hello";
	var txt = "hello the world";
	//alert(txt.replace(/^(he)+/, ""));
	alert(txt.replace(new RegExp("^("+abc+")+"), "")); */
	
	var keywords = "";
	var getAjax = false;
	var cache = {};
	jQuery( "#dealName" ).autocomplete({
		minLength: 2,
		source: function( request, response ) {
			var term = request.term;
			/* if (keywords == "") {
				keywords = term;
				getAjax = true;
			} else {
				var len = term.replace(new RegExp("^("+keywords+")+"), "").length;
				if (term.length == len) {
					getAjax = true;
					keywords = term;
				} else {
					//getAjax = false;
				}
			} */
			
			jQuery.ajax({
				url: url,
				dataType: "json",
				data: {keywords: term},
				success: function( data ) {
					cache = data;
					// Therefore, convert it to a real array
					response( jQuery.map( cache, function( value , label) {
						return {
							label: label,
							value: label,
							code: value
						}
					}));
				}
			});
		},
		select: function( event, ui ) {
			jQuery("#dealId").val(ui.item.code);
		}
	});
});